//
//  WSContentCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSContentCell.h"
#import <UIImageView+WebCache.h>

@interface WSContentCell ()

@property (nonatomic, strong) UIImageView *headImageView;

@property (nonatomic, strong) UILabel *picLabel;

@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation WSContentCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
    UIImageView *bg = [[UIImageView alloc] init];
    bg.image = [UIImage imageNamed:@"find_albumtop"];
    [self.contentView addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(@0);
        make.right.mas_equalTo(@(-3));
        make.left.mas_equalTo(@3);
        make.height.mas_equalTo(@5);
    }];
    
    self.headImageView = [[UIImageView alloc] init];
    //    self.headImageView.backgroundColor = CLEAR;
    self.headImageView.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(@5);
        make.left.right.mas_equalTo(@0);
        make.height.equalTo(self.mas_width);
    }];
    
    UIImageView *coverImage = [[UIImageView alloc] init];
    coverImage.backgroundColor = CLEAR;
    coverImage.image = [UIImage imageNamed:@"find_cover"];
    [self.headImageView addSubview:coverImage];
    
    [coverImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.mas_equalTo(@0);
        make.bottom.equalTo(self.headImageView);
        make.height.mas_equalTo(@20);
    }];
    
    self.picLabel = [[UILabel alloc] init];
    self.picLabel.backgroundColor = CLEAR;
    self.picLabel.textColor = WHITE;
    //    self.picLabel.alpha = 0.6;
    self.picLabel.font = [UIFont systemFontOfSize:12 weight:0];
    [self.headImageView addSubview:self.picLabel];
    
    [self.picLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(coverImage);
        make.left.equalTo(coverImage).offset(5);
        make.right.equalTo(coverImage).offset(-5);
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.backgroundColor = CLEAR;
    self.titleLabel.font = [UIFont systemFontOfSize:14 weight:0.1];
    self.titleLabel.text = @"纯音乐";
    self.titleLabel.textColor = [UIColor colorWithRed:0.27 green:0.27 blue:0.27 alpha:1];
    [self.titleLabel setNumberOfLines:2];
    [self.contentView addSubview:self.titleLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.mas_equalTo(@0);
        make.top.equalTo(self.headImageView.mas_bottom);
        make.bottom.equalTo(self);
    }];
}

-(void)setTextModel:(WSChildListModel *)textModel
{
    _textModel = textModel;
    NSURL *url = [NSURL URLWithString:_textModel.coverLarge];
    [self.headImageView sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    self.picLabel.text = _textModel.title;
    self.titleLabel.text = _textModel.trackTitle;
//    [self.titleLabel sizeToFit];
}

@end
